<template>
<div>
    <el-form :inline="true" :model="subform" class="demo-form-inline">
        <el-form-item label="楼栋">
            <el-select v-model="subform.buildingId" placeholder="楼栋">
                <el-option
                    v-for="item in building"
                    :label="item.buildingName"
                    :value="item.id"
                    :key="item.buildingName"
                >
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="单元">
            <el-input v-model="subform.unitName" placeholder="单元"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="checkunit">提交</el-button>
        </el-form-item>
    </el-form>
</div>
</template>

<script>
export default {
    data() {
        return {
            subform: {
                buildingId:'',
                unitName:''
            },
            building:[],
            value:'',
        }
    },
    created(){
        this.findBuilding();
    },
    methods: {
        // onSubmit() {
        //     this.$axios.post("manage/unit/checkunit",this.subform).then(res=>{
        //         if(res.data.unit==null){
        //             this.$message.success("添加成功");
        //         }
        //     })
        //
        // },
        findBuilding(){
            this.$axios.get("manage/findbuilding").then(res=>{
               this.building = res.data.buildingList;
            });
        },
        checkunit(){
            if(!this.subform.unitName){
                this.$message.error("请输入内容")
                return false;
            }
            else {
                this.$axios.post("manage/unit/checkunit",this.subform).then(res=>{
                    console.log(res.data.msg)
                    if(res.data.msg=="已存在"){
                        this.$message.error(res.data.msg)
                    }else{
                        this.$message.success(res.data.msg);
                        this.subform={};

                    }

                })
            }

        }
    }
}
</script>

<style scoped>

</style>